import 'package:bitcoin_mine/common/global.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/login_controller.dart';
import '../l10n/app_localizations.dart';
import '../routes/app_routes.dart';

class UserProfile extends StatelessWidget {
  const UserProfile({super.key});

  @override
  Widget build(BuildContext context) {
    final LoginController loginController = Get.find();
    final l10n = AppLocalizations.of(context);

    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
      child: _buildLoggedInProfile(loginController, l10n),
    );
  }

  Widget _buildLoggedInProfile(
    LoginController controller,
    AppLocalizations l10n,
  ) {
    return Row(
      children: [
        // 用户头像
        GestureDetector(
          onTap: () {
            Get.toNamed(AppRoutes.userSettings);
          },
          child: Container(
            width: 60.w,
            height: 60.w,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  const Color(0xFF0084FF).withOpacity(0.2),
                  const Color(0xFF0084FF),
                ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              ),
              shape: BoxShape.circle,
              border: Border.all(color: const Color(0xFF00FFFF), width: 2),
            ),
            child: Center(
              child: Image.asset(
                'assets/images/pic_home_top.png',
                width: 48.w,
                height: 48.w,
              ),
            ),
          ),
        ),

        SizedBox(width: 16.w),

        // 用户信息
        Expanded(
          child: Obx(() {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '# ID:${Global.user.value?.account ?? ''}',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 18.sp,
                    fontWeight: FontWeight.w600,
                  ),
                ),
                SizedBox(height: 4.h),
                Image.asset(
                  _getVipLevelRes(
                    Global.user.value?.user_info?.vip_level ?? '0',
                  ),
                  height: 22.h,
                  fit: BoxFit.cover,
                ),
                if (Global.user.value?.user_info?.vip_level != '0')
                  Text(
                    'Expires on: ${Global.user.value?.user_info?.vip_ended_at}',
                    style: TextStyle(
                      color: Colors.white.withValues(alpha: 0.5),
                      fontSize: 11.sp,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
              ],
            );
          }),
        ),

        Icon(Icons.arrow_forward_ios, color: Colors.white, size: 20.sp),
      ],
    );
  }

  String _getVipLevelRes(String level) {
    print('getVipLevelRes: $level');
    switch (level) {
      case '0':
        return 'assets/images/icon_vip_normal.png';
      case '1':
        return 'assets/images/icon_vip_basic.png';
      case '2':
        return 'assets/images/icon_vip_moderate.png';
      case '3':
        return 'assets/images/icon_vip_advanced.png';
      case '4':
        return 'assets/images/icon_vip_top.png';
      default:
        return '';
    }
  }
}
